﻿Public Class Dempresa

    Public Shared Function SeleccionarTodo(ByVal descEmpresa As String) As List(Of Eempresa)
        Dim empresas As List(Of Eempresa) = Nothing

        Using cn As New SqlConnection(ConfigurationManager.ConnectionStrings(descEmpresa).ConnectionString)
            Using cmd As New SqlCommand("usp_empresa_sel", cn)
                cmd.CommandType = CommandType.StoredProcedure
                Try
                    cn.Open()
                    Using dr As SqlDataReader = cmd.ExecuteReader(CommandBehavior.SingleResult Or CommandBehavior.CloseConnection)
                        If dr.HasRows Then
                            empresas = New List(Of Eempresa)
                            Dim accion As Eempresa = Nothing
                            Do While dr.Read
                                accion = New Eempresa( _
                                    dr.GetInt32(dr.GetOrdinal("idEmpresa")), _
                                    dr.GetString(dr.GetOrdinal("descEmpresa")), _
                                    dr.GetString(dr.GetOrdinal("estado")), _
                                    dr.GetInt32(dr.GetOrdinal("idUsuario")))
                                empresas.Add(accion)
                            Loop
                            dr.Close()
                        End If
                    End Using
                Catch ex As Exception
                    Throw
                End Try
            End Using
        End Using

        Return empresas
    End Function

End Class
